package com.zjc.app.api.sdk.client;

import com.google.gson.reflect.TypeToken;
import com.zjc.app.api.sdk.dto.GenericPageDTO;
import com.zjc.app.api.sdk.dto.ResultDto;
import com.zjc.app.api.sdk.dto.request.ApiDeviceBatchLockReqDTO;
import com.zjc.app.api.sdk.dto.request.ApiDeviceBatchUnlockReqDTO;
import com.zjc.app.api.sdk.dto.request.ApiDevicesExecuteLockRecordsReqDTO;
import com.zjc.app.api.sdk.dto.request.ApiDevicesLockRecordsPageReqDTO;
import com.zjc.app.api.sdk.dto.request.ApiDevicesLockTaskStatusReqDTO;
import com.zjc.app.api.sdk.dto.request.ApiDevicesStateReqDTO;
import com.zjc.app.api.sdk.dto.result.ApiBatchLockUnlockResultDTO;
import com.zjc.app.api.sdk.dto.result.ApiDeviceStateDTO;
import com.zjc.app.api.sdk.dto.result.ApiDevicesLockTaskStatusDTO;
import com.zjc.app.api.sdk.dto.result.ApiLockRecordCCMDTO;
import com.zjc.app.api.sdk.dto.result.ApiLockRecordDTO;
import com.zjc.app.api.sdk.exception.AppBizRuntimeException;

import java.io.IOException;
import java.util.List;

/**
 * CCM相关接口
 */
public class CCMClient extends BaseClient {

    public CCMClient(String serverUrl, String appId, String appSecret, Integer connectTimeout, Integer readTimeout) {
        super(serverUrl, appId, appSecret, connectTimeout, readTimeout);
    }

    /**
     * 批量查询终端状态和解锁机状态接口 (CCM)
     * @param request
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<List<ApiDeviceStateDTO>> getDevicesState(ApiDevicesStateReqDTO request) throws IOException, AppBizRuntimeException {
        String url = "/v1/ccm/devices/state";
        return super.doPost(url, request, new TypeToken<ResultDto<List<ApiDeviceStateDTO>>>() {});
    }

    /**
     * 批量设备停机 (CCM)
     * @param requests
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<List<ApiBatchLockUnlockResultDTO>> lockDevices(List<ApiDeviceBatchLockReqDTO> requests) throws IOException, AppBizRuntimeException {
        String url = "/v1/ccm/devices/lock";
        return super.doPost(url, requests, new TypeToken<ResultDto<List<ApiBatchLockUnlockResultDTO>>>() {});
    }

    /**
     * 批量设备开机 (CCM)
     * @param requests
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<List<ApiBatchLockUnlockResultDTO>> unlockDevices(List<ApiDeviceBatchUnlockReqDTO> requests) throws IOException, AppBizRuntimeException {
        String url = "/v1/ccm/devices/unlock";
        return super.doPost(url, requests, new TypeToken<ResultDto<List<ApiBatchLockUnlockResultDTO>>>() {});
    }

    /**
     * 成功状态的解锁车记录(列表)批量查询接口 (查询每个设备的最新数据) (CCM)
     * @param request
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<GenericPageDTO<ApiLockRecordDTO>> getDevicesSuccessLockUnlockRecordsNewest(ApiDevicesLockRecordsPageReqDTO request) throws IOException, AppBizRuntimeException {
        String url = "/v1/ccm/devices/lock_unlock/records/success/newest/page";
        return super.doPost(url, request, new TypeToken<ResultDto<GenericPageDTO<ApiLockRecordDTO>>>() {});
    }

    /**
     * 批量查询开机/锁机指令最新状态接口
     * @param requests
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<List<ApiDevicesLockTaskStatusDTO>> getLockTaskStatusList(List<ApiDevicesLockTaskStatusReqDTO> requests) throws IOException, AppBizRuntimeException {
        String url = "/v1/ccm/devices/lock_unlock/status";
        return super.doPost(url, requests, new TypeToken<ResultDto<List<ApiDevicesLockTaskStatusDTO>>>() {});
    }

    /**
     * 查询待执行、执行中停开机任务接口
     * @param request
     * @return
     * @throws IOException
     * @throws AppBizRuntimeException
     */
    public ResultDto<List<ApiLockRecordCCMDTO>> getDevicesExecuteLockUnlockRecords(ApiDevicesExecuteLockRecordsReqDTO request) throws IOException, AppBizRuntimeException {
        String url = "/v1/ccm/devices/lock_unlock/records/execute";
        return super.doPost(url, request, new TypeToken<ResultDto<List<ApiLockRecordCCMDTO>>>() {});
    }
}
